home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DTP
/
DTP_TEX
/
3238.ZIP
/
DVIEPS2.ZIP
/
DVIBIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-12-01
|
8KB
|
293 lines
/*=======================================================================
* Program : dvibit.c
* Purpose : bitmap related code for eps device driver
* Date : Oct 1988
*========================================================================
* Compiler : Microsoft V5.1 C Compiler
* Linker : Microsoft V3.61 Linker
* Enviroment : MS-DOS 3.21
*========================================================================
* Edit History
*
* / / -gbm-
*
*======================================================================*/
#include "dvidefs.h"
#include "dvivars.h"
#include <sys\types.h>
#include <sys\stat.h>
#include <fcntl.h>
extern double mag_table[99];
void getbmap()
{
int i;
char *tcp;
char fname[100];
if (bitmap == (unsigned long int*)NULL)
{
bitmap = malloc(25000);
if (bitmap == (char *)NULL)
(void)fatal("getbmap(): Cannot allocate space for page image bitmap");
if ((tcp = getenv("EPSBMAP")) == (char *)NULL)
strcpy(fname, "BMAP.TMP");
else
strcpy(fname, tcp);
bmap_file = open(fname, O_BINARY | O_CREAT | O_TRUNC | O_RDWR ,S_IREAD | S_IWRITE);
if (bmap_file == -1)
(void)fatal("getbmap(): Cannot allocate temporary file");
clrbmap();
}
}
void clrbmap()
{
int i;
lseek(bmap_file, 0L, SEEK_SET);
for (i=0; i<25; i++)
{
memset((char *)bitmap, 0, 24000);
if (write(bmap_file, (char*)bitmap, 24000) != 24000)
(void)fatal("getbmap(): Cannot clear temporary file");
}
memset((char *)bitmap, 0, 24000);
y_file = 0;
y_min = 5000;
y_max = -1; /* ???????????????? */
}
/* return a long int pointer to the yth block of 1920 bits */
/* these pointers are read in 24000 bytes at a time */
unsigned long int *rd_bitmap(int y, int x)
{
int new_y, bl, tt;
long int li;
if (x < 0 || y < 0 || x > 60 || y > 2376)
{
printf("\nBitmap read out of range X = %d, Y = %d\n", x, y);
(void)fatal("rd_bitmap(): Out of range pointer");
}
if (y < y_min || y > y_max)
{
/* flush current */
lseek(bmap_file, 240L * (long int)y_file, SEEK_SET);
if (write(bmap_file, (char*)bitmap, 24000) != 24000)
(void)fatal("rd_bitmap(): Cannot flush bitmap");
/* get the new position 30 rasters less than expected*/
tt = y - 30;
if (tt < 0)
new_y = 0;
else
new_y = tt;
y_min = new_y;
y_max = new_y + 100;
lseek(bmap_file, 240L * (long int)new_y, SEEK_SET);
if ((bl = (unsigned int)read(bmap_file, (char*)bitmap, 24000)) != 24000)
{
printf("\n<%d bytes read, should be 24000>", bl);
(void)fatal("rd_bitmap(): Cannot read bitmap");
}
// printf("(%d->%d=%d)", y_file, new_y, y);
y_file = new_y;
}
return (long int *)((long int)bitmap +
(y - y_file) * 240L + (long int)(x * 4));
}
void prtbmap()
{
register int i;
int j;
int l;
int ybottom;
int ytop;
int second = 0; /* address second byte if not zero */
int k32;
unsigned long int bitwise[24][XSIZE/32]; /* block of main bitmap */
unsigned long int maskl;
unsigned char r[3][XSIZE]; /* vertical 8-bit raster encodings */
unsigned char maskc;
unsigned long int *p; /* pointer into bitmap[][] */
int k;
fprintf(stderr, "p");
if (kbhit())
{
getch();
(void)fatal("prtbmap(): Operator abort");
}
(void)clearerr(plotfp);
ytop = YBIT - 1;
ybottom = 0;
paperfeeding = 0; /* for outpaperfeed() */
(void)fprintf(plotfp, "\0333%c", 0); /* no paperfeeding */
for (j = ytop - 24; j >= ybottom; j -= 24)
{
for (k = 0, i = 24; k < 24; k++, i--)
{
p = rd_bitmap(j+i, 0);
(void)memcpy((char *)bitwise[k], (char *)p, XSIZE/8);
}
(void)memset(r[0], 0, XSIZE);
(void)memset(r[1], 0, XSIZE);
(void)memset(r[2], 0, XSIZE);
maskl = 0x80000000L; /* just in case */
for (k = 0; k < XSIZE; k++)
{
if ((k % 32) == 0)
maskl = 0x80000000L;
k32 = k / 32;
maskc = 0x80;
if (bitwise[0][k32] & maskl)
r[0][k] |= maskc;
if (bitwise[1][k32] & maskl)
r[1][k] |= maskc;
if (bitwise[2][k32] & maskl)
r[2][k] |= maskc;
maskc >>= 1;
if (bitwise[3][k32] & maskl)
r[0][k] |= maskc;
if (bitwise[4][k32] & maskl)
r[1][k] |= maskc;
if (bitwise[5][k32] & maskl)
r[2][k] |= maskc;
maskc >>= 1;
if (bitwise[6][k32] & maskl)
r[0][k] |= maskc;
if (bitwise[7][k32] & maskl)
r[1][k] |= maskc;
if (bitwise[8][k32] & maskl)
r[2][k] |= maskc;
maskc >>= 1;
if (bitwise[9][k32] & maskl)
r[0][k] |= maskc;
if (bitwise[10][k32] & maskl)
r[1][k] |= maskc;
if (bitwise[11][k32] & maskl)
r[2][k] |= maskc;
maskc >>= 1;
if (bitwise[12][k32] & maskl)
r[0][k] |= maskc;
if (bitwise[13][k32] & maskl)
r[1][k] |= maskc;
if (bitwise[14][k32] & maskl)
r[2][k] |= maskc;
maskc >>= 1;
if (bitwise[15][k32] & maskl)
r[0][k] |= maskc;
if (bitwise[16][k32] & maskl)
r[1][k] |= maskc;
if (bitwise[17][k32] & maskl)
r[2][k] |= maskc;
maskc >>= 1;
if (bitwise[18][k32] & maskl)
r[0][k] |= maskc;
if (bitwise[19][k32] & maskl)
r[1][k] |= maskc;
if (bitwise[20][k32] & maskl)
r[2][k] |= maskc;
maskc >>= 1;
if (bitwise[21][k32] & maskl)
r[0][k] |= maskc;
if (bitwise[22][k32] & maskl)
r[1][k] |= maskc;
if (bitwise[23][k32] & maskl)
r[2][k] |= maskc;
maskl >>= 1;
}
outline((char *)&r[0][0]);
(void)outpaperfeed(1);
outline((char *)&r[1][0]);
(void)outpaperfeed(1);
outline((char *)&r[2][0]);
(void)outpaperfeed(22);
}
(void)fputs("\0332", plotfp); /* ESC 2 = normal paperfeeding */
(void)putc((char)('\f'), plotfp); /* eject page with FF */
(void)fflush(plotfp);
if (DISKFULL(plotfp))
(void)fatal("prtbmap(): Output error -- disk storage probably full");
}
void outline(pline)
char *pline;
{
register char* a;
register char* b;
register char* c;
register int left;
int len;
int linelength;
char resolution;
unsigned char spacing;
unsigned char space_width;
linelength = XSIZE;
for ((left = XSIZE, c = pline + linelength - 1);
(*c == '\000') && (left > 0);
(--left, --c)) /* trim white space */
;
if (left == 0)
return; /* NEWLINE() is not needed for any paperfeeding */
(void)outpaperfeed(0); /* print accumulated paperfeedings */
if (left > 0)
{
(void)fprintf(plotfp, "\033*%c%c%c", 3, left % 256, left / 256);
for (c = pline; left; --left, c++)
(void)putc((char)(*c), plotfp);
}
/* (void)putc((char)10, plotfp); fix by NEP 88-12-01 */
(void)putc((char)13, plotfp);
}
void outpaperfeed(count) /* accumulate 1/216 inch paperfeedings */
int count; /* and write them out if count == 0 */
{
register int k;
if (count)
paperfeeding += count;
else
{
for (k = paperfeeding / 255; k; --k)
(void)fprintf(plotfp, "\033J%c", 255);
if ((k = paperfeeding % 255) > 0)
(void)fprintf(plotfp, "\033J%c", k);
paperfeeding = 0;
}
}